package com.lamatek.tags.google;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import com.lamatek.tags.google.beans.EscapeChars;

/**
 * GoogleMapLabelTag
 * 
 * Represents a &lt;googlemaps:label> tag. Developers should not extend this class
 * or override it's methods.
 */
public class GoogleMapLabelTag extends BodyTagSupport {

    String point = null;
    String css_class = null;
    String style = null;
    String content = null;
    boolean html = true;
    float opacity = 0.5f;
    int x_offset = 0;
    int y_offset = 0;
    /**
     * Overrides doStartTag() from BodyTagSupport.
     */
    public int doStartTag() {
        return EVAL_BODY_BUFFERED;
    }
    /**
     * Overrides doEndTag() from BodyTagSupport.
     */
    public int doEndTag() {
        if (content == null) {
            content = getBodyContent().getString().trim();
            if (html)
                content = EscapeChars.escape(content);
        }
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).addLabel(this);
                return EVAL_PAGE;
            }
            tag = tag.getParent();
        }
        return EVAL_PAGE;
    }
    /**
     * Returns the current css class attribute for this label.
     * 
     */
    public String getCss_class() {
        return css_class;
    }
    /**
     * Sets the css class attribute for this label's surrounding div.
     */
    public void setCss_class(String css_class) {
        this.css_class = css_class;
    }
    /**
     * Returns the point tag that determines where this label is placed.
     */
    public String getPoint() {
        return point;
    }
    /**
     * Sets the point tag that determines where this label is placed. Must be a 
     * valid point id.
     */
    public void setPoint(String point) {
        this.point = point;
    }
    /**
     * Returns the current css style attribute for this label's surrounding div.
     */
    public String getStyle() {
        return style;
    }
    /**
     * Sets the css style attribute for this label's surrounding div.
     */
    public void setStyle(String style) {
        this.style = style;
    }
    /**
     * Returns the text content for this label.
     */
    public String getContent() {
        return content;
    }
    /**
     * Returns the text content for this label.
     */
    public void setContent(String content) {
        if (html)
            this.content = EscapeChars.escape(content.trim());
        else
            this.content = content.trim();
    }
    /**
     * Returns true if this label content is in html, false otherwise.
     */
    public boolean isHtml() {
        return html;
    }
    /**
     * Denotes whether or not content for this label is html.
     */
    public void setHtml(boolean html) {
        this.html = html;
    }
    /**
     * Returns the current opacity level (0-1) for this label.
     */
    public float getOpacity() {
        return opacity;
    }
    /**
     * Sets the opacity level (0-1) for this label.
     */
    public void setOpacity(float opacity) {
        this.opacity = opacity;
    }
    /**
     * Returns the left/right offset (in pixels) from the point to place this
     * label. Negative is left, positive is right.
     */
    public int getX_offset() {
        return x_offset;
    }
    /**
     * Sets the left/right offset (in pixels) from the point to place this
     * label. Negative is left, positive is right.
     */
    public void setX_offset(int x_offset) {
        this.x_offset = x_offset;
    }
    /**
     * Returns the up/down offset (in pixels) from the point to place this
     * label. Negative is up, positive is down.
     */
    public int getY_offset() {
        return y_offset;
    }
    /**
     * Sets the up/down offset (in pixels) from the point to place this
     * label. Negative is up, positive is down.
     */
    public void setY_offset(int y_offset) {
        this.y_offset = y_offset;
    }
}
